home *** CD-ROM | disk | FTP | other *** search
- // Dynamic link library implementation of NeuroSolutions SquareKohonen component
-
- #include "NSDLL.h"
-
- /*************************************************************/
- /* Macros to access the PE layers and weights in matrix form */
-
- #define in(i,j) input[j+i*inCols]
- #define out(i,j) output[j+i*outCols]
- #define W(i,j) weights[j+i*inCount]
-
- /******************************/
- /* Unsupervised weight update */
-
- __declspec(dllexport) void performKohonen(
- DLLData *instance, // Pointer to instance data (may be NULL)
- NSFloat *input, // Pointer to input layer
- int inRows, // Number of rows of PEs in the input layer
- int inCols, // Number of columns of PEs in the input layer
- NSFloat *output, // Pointer to output layer
- int outRows, // Number of rows of PEs in the output layer
- int outCols, // Number of columns of PEs in the output layer
- NSFloat *weights, // Pointer to fully connected weight matrix
- NSFloat step, // Learning rate
- int winningRow, // Index of winning row
- int winningCol, // Index of winning column
- int size // Size of the neighborhood
- )
- {
- int i,j,k,
- inCount = inRows*inCols,
- startRow = winningRow - size,
- stopRow = winningRow + size,
- startCol = winningCol - size,
- stopCol = winningCol + size;
-
- if (startRow < 0)
- startRow = 0;
- if (stopRow >= outRows)
- stopRow = outRows-1;
- if (startCol < 0)
- startCol = 0;
- if (stopCol >= outCols)
- stopCol = outCols-1;
- for (i=startRow; i<=stopRow; i++)
- for (j=startCol; j<=stopCol; j++)
- for (k=0; k<inCount; k++)
- W(j+i*outCols,k) += step*(input[k] - W(j+i*outCols,k));
- }
-
- /******************************************/
- /* Management of instance data (OPTIONAL) */
- /*
- __declspec(dllexport) DLLData *allocKohonen(
- DLLData *oldInstance, // Pointer to the last instance if reallocating
- int inRows, // Number of rows of PEs in the input layer
- int inCols, // Number of columns of PEs in the input layer
- int outRows, // Number of rows of PEs in the output layer
- int outCols // Number of columns of PEs in the output layer
- )
- {
- DLLData *instance = allocDLLInstance(oldInstance);
- return instance;
- }
-
- __declspec(dllexport) void freeKohonen(DLLData *instance)
- {
- freeDLLInstance(instance);
- }
- */